#include "BackpropagationConnector.h"
#include "BackpropagationSynapse.h"

using namespace NeuralPlusPlus::Core;
using namespace NeuralPlusPlus::Core::Backpropagation;

NeuralPlusPlus::Core::Backpropagation::BackpropagationConnector::BackpropagationConnector( ActivationLayer *sourceLayer, ActivationLayer *targetLayer, ConnectionModeType connectionMode /*= ConnectionModeType::Complete*/ ) : Connector(sourceLayer, targetLayer, connectionMode)
	{
		this->Momentum = 0.07;
		ConstructSynapses();
	}

void NeuralPlusPlus::Core::Backpropagation::BackpropagationConnector::Initialize()
	{
	if (Initializer != NULL)
		{
		Initializer->Initialize(this);
		}
	}

void NeuralPlusPlus::Core::Backpropagation::BackpropagationConnector::ConstructSynapses()
	{
	int targetLayerNeuronLength = TargetLayer->NeuronsLength;
	int sourceLayerNeuronLength = SourceLayer->NeuronsLength;
	switch(ConnectionMode)
		{
		case ConnectionModeType::Complete:
			for (int i = 0; i < targetLayerNeuronLength;i++ )
				{
				ActivationNeuron *targetNeuron = (ActivationNeuron*)(*TargetLayer)[i];
				for (int j = 0; j < sourceLayerNeuronLength;j++ )
					{
					ActivationNeuron *sourceNeuron = (ActivationNeuron*)(*SourceLayer)[j];
					Synapses[i * sourceLayerNeuronLength + j] = new BackpropagationSynapse(sourceNeuron, targetNeuron, this);
					}
				}
			break;
		case ConnectionModeType::OneOne:
			for (int i = 0; i < targetLayerNeuronLength;i++ )
				{
				ActivationNeuron *targetNeuron = (ActivationNeuron*)(*TargetLayer)[i];
				ActivationNeuron *sourceNeuron = (ActivationNeuron*)(*SourceLayer)[i];
				Synapses[i] = new BackpropagationSynapse(sourceNeuron, targetNeuron, this);
				}
			break;
		}
	}